<template>
  <div class="app-container h-flex">
    <div class="tree-box app-container__left">
      <div class="type-title h-flex">
        <div class="h-flex-elastic type-title-item">业务类型</div>
      </div>
      <el-tree
        v-if="bizTypeTree.length>0"
        ref="tree_box"
        :data="bizTypeTree"
        node-key="id"
        icon-class="el-icon-arrow-right"
        :expand-on-click-node="false"
        default-expand-all
        :current-node-key="listQuery.errorType"
        :props="defaultDeptProps"
        @node-click="queryNodeClick" />
    </div>
    <div ref="container" class="app-container__right h-flex-elastic v-flex overflow-hidden">
      <filter-form only-query :form="listQuery" :data="filterData" @search="search">
        <template v-if="listQuery.status === 0 && listQuery.key">
          <el-button size="mini" type="primary" @click="reVerify">重新校验</el-button>
        </template>
        <template v-if="hasValue(addtionalParams)">
          <el-button size="mini" type="warning" @click="addtionalParams={};getListPage()">清除额外条件</el-button>
          <span style="font-size:14px;margin-left:10px;color:#e6a23c;">额外条件：{{ addtionalParams }}</span>
        </template>
      </filter-form>
      <div ref="main" class="v-flex-elastic">
        <el-table
          v-loading="listLoading"
          :data="tableData"
          border
          tooltip-effect="dark"
          style="width: 100%"
          :height="height">
          <el-table-column label="序号" align="center" type="index" width="50" />
          <el-table-column show-overflow-tooltip align="center" prop="bizTypeName" label="业务类型" width="150">
            <template slot-scope="{row}">
              {{ row.parentBizTypeName }}<br>{{ row.bizTypeName }}
            </template>
          </el-table-column>
          <el-table-column label="错误信息">
            <el-table-column show-overflow-tooltip align="center" prop="consumerErrorList.collKeyMemo" label="错误类型" width="80">
              <template slot-scope="{row}">
                <div v-for="item in row.consumerErrorList" :key="item.errorCode">
                  {{ item.errorTypeName }}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip align="center" prop="consumerErrorList.collKey" label="错误原因" width="120">
              <template slot-scope="{row}">
                <div v-for="item in row.consumerErrorList" :key="item.errorCode">
                  {{ item.errorReason }}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip align="center" prop="consumerErrorList.collKeyType" label="错误编码" width="150">
              <template slot-scope="{row}">
                <div v-for="item in row.consumerErrorList" :key="item.errorCode">
                  {{ item.errorCode }}
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip align="center" prop="consumerErrorList.collKeyType" label="状态" width="80">
              <template slot-scope="{row}">
                <div v-for="item in row.consumerErrorList" :key="item.errorCode">
                  <span :style="{color: item.status ? '#1fe41f' : 'red'}">
                    {{ item.status ? '已处理' : '未处理' }}
                  </span>
                </div>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip align="center" prop="consumerErrorList.collKeyType" label="校正数据">
              <template slot-scope="{row}">
                <div v-for="item in row.consumerErrorList" :key="item.errorCode">
                  <span v-if="item.correctData" slot="message" style="cursor: pointer;" @click="showJson(JSON.stringify(item.correctData))">
                    {{ JSON.stringify(item.correctData).slice(0, 50) }}
                  </span>
                  <span v-else>-</span>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column show-overflow-tooltip align="center" prop="errorDate" label="错误时间" width="180" />
          <el-table-column show-overflow-tooltip align="center" prop="errorData" label="源数据">
            <template slot-scope="{row}">
              <span slot="message" style="cursor: pointer;" @click="showJson(JSON.stringify(row.errorData))">
                {{ JSON.stringify(row.errorData).slice(0, 50) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="handleDate" show-overflow-tooltip label="处理时间" width="180" />
          <el-table-column show-overflow-tooltip align="center" prop="errorData" label="状态" width="80">
            <template slot-scope="{row}">
              <span :style="{color: row.status ? '#1fe41f' : 'red'}">
                {{ row.status ? '完成' : '待预处理' }}
              </span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip align="center" prop="operations" label="操作" width="80" fixed="right">
            <template slot-scope="{row}">
              <el-button
                size="mini"
                class="td-btn-operation"
                @click="startCorrect(row, 0)">校正</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- <base-table
          :height="height"
          :loading="listLoading"
          :data="tableData"
          :columns="columns"
          show-filter-column
          :default-operations="[]">
          <span slot="message" slot-scope="{row}" style="cursor: pointer;" @click="showJson(row)">
            {{ row.message.slice(0, 30) }}
          </span>
          <template slot="status" slot-scope="{row}">
            <span :style="{color: row.status ? '#1fe41f' : 'red'}">
              {{ row.status ? '已处理' : '未处理' }}
            </span>
          </template>
          <template slot="operations" slot-scope="{row}">
            <el-button
              v-if="row.errorType && row.errorType !== 'OTHER' && !row.status"
              size="mini"
              class="td-btn-operation"
              @click="correct(row)">校正</el-button>
          </template>
        </base-table> -->
      </div>
      <div class="page-box">
        <pagination
          :total="total"
          :page.sync="listQuery.page"
          :size.sync="listQuery.size"
          @pagination="getListPage" />
      </div>
    </div>
    <base-dialog
      class="pretreatment-data-dialog"
      width="92%"
      confirm-text="确认修改"
      :visible.sync="dialog.visible"
      :title="dialog.title"
      :loading="dialog.loading"
      :show-default-footer="false"
      @close="beforeCloseDialog"
      @open="beforeOpenDialog"
      @updateData="updateData">
      <div class="pretreatment-data-dialog-box">
        <div class="pretreatment-data-dialog-left">
          <p class="error-title">原始数据：</p>
          <el-scrollbar class="view_json">
            <json-viewer
              class="v-flex-elastic"
              :value="viewJson"
              :expand-depth="5"
              copyable
              sort />
          </el-scrollbar>
        </div>
        <div class="pretreatment-data-dialog-middle">
          <el-radio-group v-model="stepActive" fill="#409EFF" @change="handleClickError">
            <el-radio-button v-for="(item, index) in currentRowObj.consumerErrorList" :key="index" :label="index">
              <span><i :class="item.status?'el-icon-circle-check':'el-icon-warning-outline'" /> {{ item.errorTypeName }}校正</span>
            </el-radio-button>
          </el-radio-group>
          <el-scrollbar class="view_con">
            <div v-if="dialog.form.errorType">
              <el-form
                ref="dataForm"
                class="v-flex-elastic"
                :model="dialog.form"
                :rules="currentErrorType.rules || dialog.rules"
                :label-width="dialog.form.errorCode ? '110px' : currentErrorType.labelWidth || '90px'">
                <el-row>
                  <el-col :span="4">
                    <el-form-item v-if="dialog.form.errorCode" label="是否形成规则">
                      <el-switch v-model="dialog.form.ruleFlag" :active-value="1" :inactive-value="0" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item :label="currentErrorType.name" prop="collectionName">
                      <el-input v-model="dialog.form.collectionName" clearable style="width: 100%" disabled placeholder="请在下面表格选择" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <p v-if="dialog.form.errorCode" class="error-sub-title" @click="showDetail">
                      同类错误处理条数：<span>{{ dialog1.total }}</span>（点击查看）
                    </p>
                  </el-col>
                </el-row>
              </el-form>
              <filter-form
                :form="currentErrorType.filterForm"
                :data="currentErrorType.filterData"
                :only-query="true"
                @search="currentErrorTypeSearch" />
              <base-table
                height="360px"
                :loading="listLoading"
                :data="selectData"
                :columns="currentErrorType.columns"
                :show-operation="false"
                show-filter-column
                :row-style="rowstyle"
                :row-show-color="currentErrorType.rowShowColor"
                @row-click="handleRowClick" />
              <div class="page-box">
                <pagination
                  :total="currentErrorType.total"
                  :page.sync="currentErrorType.filterForm.page"
                  :size.sync="currentErrorType.filterForm.size"
                  @pagination="currentErrorTypePage" />
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateData">保存</el-button>
      </span>
    </base-dialog>
    <base-dialog
      class="pretreatment-data-dialog1"
      width="92%"
      :visible.sync="dialog1.visible"
      :title="dialog1.title"
      :show-default-footer="false">
      <el-table
        v-loading="dialog1.listLoading"
        class="v-flex-elastic"
        :data="dialog1.tableData"
        border
        height="calc(80vh - 225px)"
        tooltip-effect="dark"
        style="width: 100%;">
        <el-table-column label="序号" align="center" type="index" width="50" />
        <el-table-column prop="errorReason" show-overflow-tooltip label="错误原因" />
        <el-table-column
          prop="errorType"
          :formatter="row => {
            const item = errorTypeList.filter(item => item.code === row.errorType)[0]
            return item && item.name
          }"
          show-overflow-tooltip
          label="错误类型" />
        <el-table-column prop="errorCode" show-overflow-tooltip label="错误编码" />
        <el-table-column prop="errorDate" show-overflow-tooltip label="错误时间" />
        <el-table-column prop="message" show-overflow-tooltip label="源数据">
          <template slot-scope="{row}">
            <span style="cursor: pointer;" @click="showJson(row)">
              <!-- {{ row.message.slice(0, 30) }} -->
            </span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="状态">
          <template slot-scope="{row}">
            <span :style="{color: row.status ? '#1fe41f' : 'red'}">
              {{ row.status ? '已处理' : '未处理' }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <div class="page-box">
        <pagination
          style="background: transparent;"
          :total="dialog1.total"
          :page.sync="dialog1.listQuery.page"
          :size.sync="dialog1.listQuery.size"
          @pagination="getErrorList" />
      </div>
    </base-dialog>
    <base-dialog
      class="pretreatment-data-dialog2"
      width="92%"
      :visible.sync="dialog2.visible"
      :title="dialog2.title"
      :show-default-footer="false">
      <div class="json-viewer-container">
        <json-viewer
          :value="viewJson"
          :expand-depth="5"
          copyable
          sort />
      </div>
    </base-dialog>
  </div>
</template>
<script>
import {
  getListPage,
  getErrorType,
  getErrorList,
  saveRule,
  getListBizTypeTree,
  reVerify,
  getworkAreaList,

  getworkAreaPage,
  getLineListPage as lineList,
  getLineList,
  getSiteListByLineId as getSiteList,
  getSiteList as siteList,
  getDirectionPage as directionList,
  getPillarList as pillarList,
  getTrackList as trackList,
  getTunnelList as tunnelList,
  getAnchorList as anchorList,
  getAllTunnelList,
  getDirectionList,
  getDefectTypePage,
  getDefectGradePage
} from '@/api/cms/pretreatment/pretreatment-data'
import { getListTree as devClassList } from '@/api/dsc/equipment-resume/species'
import { getDept as departmentList } from '@/api/dsc/system/department'
import { directionList as getAllDirectionList } from '@/api/dsc/location-area-info/direction-diff'
import { getListPage as deviceList } from '@/api/dsc/equipment-resume/device'
import { getListPage as device6cList } from '@/api/dsc/equipment-resume/6c-device'
import JsonViewer from 'vue-json-viewer'
import { tableMixin } from '@/utils/public'
import { deepClone } from '@/utils'
export default {
  name: 'PretreatmentData',
  components: { JsonViewer },
  mixins: [tableMixin],
  data() {
    return {
      bizTypeTree: [],
      defaultDeptProps: {
        children: 'children',
        label: 'label',
        id: 'id'
      },
      columns: [
        { label: '来源接口', prop: 'bizTypeName' },
        { label: '错误原因', prop: 'errorReason' },
        { label: '错误类型', prop: 'errorType', formatter: row => this.errorTypeList.filter(item => item.code === row.errorType)[0].name },
        { label: '错误编码', prop: 'errorCode' },
        { label: '错误时间', prop: 'errorDate' },
        { label: '源数据', prop: 'message', template: true },
        { label: '状态', prop: 'status', template: true },
        { label: '处理时间', prop: 'handleDate' }
      ],
      stepActive: 0,
      listQuery: {
        page: 1,
        size: 20,
        errorType: '',
        status: 0
      },
      addtionalParams: {},
      filterData: {
        status: {
          key: 'status',
          type: 'select',
          placeholder: '状态',
          clearable: false,
          options: [
            { label: '完成', value: 1 },
            { label: '待预处理', value: 0 }
          ]
        },
        errorType: {
          key: 'errorType',
          type: 'select',
          title: '错误类型',
          placeholder: '错误类型',
          props: { label: 'name', value: 'type' },
          options: []
        }
      },
      height: 0,
      listLoading: true,
      tableData: [],
      total: 0,
      dialog: {
        title: '修改',
        visible: false,
        loading: false,
        form: {
          data: {},
          errorType: '',
          errorCode: ''
        },
        rules: {
          data: { type: 'object', required: true, validator: (rule, value, callback) => {
            if (Object.keys(value).length) {
              callback()
            } else {
              callback(new Error('请选择'))
            }
          }, trigger: 'change' }
        }
      },
      dialog1: {
        title: '同类错误数据',
        visible: false,
        tableData: [],
        total: 0,
        listQuery: {
          page: 1,
          size: 10
        },
        listLoading: true
      },
      dialog2: {
        title: '源数据',
        visible: false
      },
      errorTypes: {
        DEPT: {
          chooseType: 'selectTable',
          type: 'DEPT',
          key: 'deptName',
          name: '部门',
          rowShowColor: {
            name: 'deptName',
            vlaue: null
          },
          interface: getworkAreaPage,
          list: [],
          data: {
            deptId: 'deptId',
            deptCode: 'deptCode',
            deptName: 'deptName',
            parentCode: 'parentCode'
          },
          filterForm: {
            deptName: '',
            dataSysnKey: '',
            page: 1,
            size: 20
          },
          filterData: {
            deptName: {
              key: 'deptName',
              type: 'input',
              placeholder: '部门'
            }
          },
          columns: [
            { label: '部门名称', property: 'deptName', formatter: row => row.deptName ? row.deptName : '' },
            { label: '部门编号', property: 'deptCode', formatter: row => row.deptNo ? row.deptNo : '' }
          ],
          total: 0
        },
        LINE: {
          chooseType: 'selectTable',
          type: 'LINE',
          key: 'lineName',
          name: '线路',
          interface: lineList,
          list: [],
          data: {
            lineId: 'id',
            lineCode: 'lineCode',
            lineName: 'lineName'
          },
          filterForm: {
            dataSysnKey: '',
            lineName: '',
            page: 1,
            size: 20
          },
          filterData: {
            lineName: {
              key: 'lineName',
              type: 'input',
              placeholder: '线路'
            }
          },
          columns: [
            { label: '线路', property: 'seclineName', formatter: row => row.seclineName ? row.seclineName : '' },
            { label: '铁路类别', property: 'railType', formatter: row => row.railType ? row.railType : '' },
            { label: '线路等级', property: 'lineLevel', formatter: row => row.lineLevel ? row.lineLevel : '' },
            { label: '线路类型', property: 'seclineType', formatter: row => row.seclineType ? row.seclineType : '' }
          ],
          total: 0
        },
        LINE_SITE: {
          chooseType: 'selectTable',
          type: 'LINE_SITE',
          key: 'siteName',
          name: '区间站场',
          interface: siteList,
          list: [],
          data: {
            siteId: 'id',
            // siteId: 'siteId',
            lineSiteCode: 'lineSiteCode',
            siteName: 'siteName',
            lineId: 'lineId'
          },
          filterForm: {
            dataSysnKey: '',
            lineId: '',
            siteName: '',
            page: 1,
            size: 20
          },
          filterData: {
            lineId: {
              key: 'lineId',
              type: 'selectTree',
              title: '线路',
              placeholder: '所有线路',
              options: [],
              props: {
                label: 'label',
                value: 'id',
                parent: 'parentId',
                children: 'children'
              },
              changeFn: (vm, node) => {
              }
            },
            siteName: {
              key: 'siteName',
              type: 'input',
              placeholder: '区间站场'
            }
          },
          columns: [
            { property: 'siteName', label: '区间站场', formatter: row => row.siteName ? row.siteName : '' },
            { property: 'lineName', label: '所属线路', formatter: row => row.lineName ? row.lineName : '' },
            { property: 'directionName', label: '行别', formatter: row => row.directionName ? row.directionName : '' }
          ],
          total: 0
        },
        DIRECTION: {
          chooseType: 'selectTable',
          type: 'DIRECTION',
          key: 'directionName',
          name: '行别',
          interface: directionList,
          list: [],
          data: {
            directionId: 'id',
            directionCode: 'directionCode',
            directionName: 'directionName'
          },
          filterForm: {
            dataSysnKey: '',
            directionName: '',
            page: 1,
            size: 20
          },
          filterData: {
            keyName: {
              key: 'directionName',
              type: 'input',
              placeholder: '行别名称、编号、备注'
            }
          },
          columns: [
            { property: 'directionName', label: '行别', formatter: row => row.directionName ? row.directionName : '' }
          ],
          total: 0
        },
        TRACK: {
          chooseType: 'selectTable',
          type: 'TRACK',
          key: 'trackName',
          name: '股道',
          interface: trackList,
          list: [],
          data: {
            trackId: 'id',
            trackCode: 'trackCode',
            trackName: 'trackName',
            lineList: 'lineList',
            siteId: 'siteId',
            directionId: 'directionId'
          },
          filterForm: {
            dataSysnKey: '',
            trackName: '',
            page: 1,
            size: 20
          },
          filterData: {
            lineId: {
              key: 'lineId',
              type: 'selectTree',
              title: '线路',
              placeholder: '所有线路',
              options: [],
              props: {
                label: 'label',
                value: 'id',
                parent: 'parentId',
                children: 'children'
              },
              changeFn: (vm, node) => {
                this.currentErrorType.filterForm.siteId = ''
                this.errorTypes.TRACK.filterData['siteId'].options = []
                if (!node.id) return
                getSiteList({
                  dataSysnKey: this.currentRowObj.key,
                  lineId: node.id
                })(response => {
                  this.errorTypes.TRACK.filterData['siteId'].options = Object.freeze(response.data)
                })
              },
              clearFn: () => {
                this.currentErrorType.filterForm.siteId = ''
                this.errorTypes.TRACK.filterData['siteId'].options = []
              }
            },
            siteId: {
              key: 'siteId',
              type: 'select',
              title: '区间站场',
              placeholder: '所有区间站场',
              options: [],
              props: {
                label: 'siteName',
                value: 'siteId'
              },
              changeFn: () => {
              }
            },
            directionId: {
              key: 'directionId',
              type: 'select',
              title: '行别',
              placeholder: '所有行别',
              options: [],
              props: {
                label: 'directionName',
                value: 'id'
              },
              changeFn: () => {
              }
            },
            trackName: {
              key: 'trackName',
              type: 'input',
              placeholder: '股道'
            }
          },
          columns: [
            { property: 'trackName', label: '股道', formatter: row => row.trackName ? row.trackName : '' },
            { property: 'lineName', label: '线路', formatter: row => row.lineName ? row.lineName : '' },
            { property: 'siteName', label: '区间站场', formatter: row => row.siteName ? row.siteName : '' },
            { property: 'beginRoad', label: '起始公里标', formatter: row => this.formatRoad(row.beginRoad) },
            { property: 'endRoad', label: '结束公里标', formatter: row => this.formatRoad(row.endRoad) }
          ],
          total: 0
        },
        TUNNEL: {
          chooseType: 'selectTable',
          type: 'TUNNEL',
          key: 'tunnelName',
          name: '隧道',
          interface: tunnelList,
          list: [],
          data: {
            tunnelId: 'id',
            tunnelCode: 'tunnelCode',
            tunnelName: 'tunnelName',
            lineId: 'lineId',
            siteIds: 'siteIds',
            directionIds: 'directionIds'
          },
          filterForm: {
            dataSysnKey: '',
            lineId: '',
            siteId: '',
            tunnelName: '',
            directionId: '',
            page: 1,
            size: 20
          },
          filterData: {
            lineId: {
              key: 'lineId',
              type: 'selectTree',
              title: '线路',
              placeholder: '所有线路',
              options: [],
              props: {
                label: 'label',
                value: 'id',
                parent: 'parentId',
                children: 'children'
              },
              changeFn: (vm, node) => {
                this.errorTypes.TUNNEL.filterForm.siteId = ''
                this.errorTypes.TUNNEL.filterData['siteId'].options = []
                if (!node.id) return
                getSiteList({
                  dataSysnKey: this.currentRowObj.key,
                  lineId: node.id
                })(response => {
                  this.errorTypes.TUNNEL.filterData['siteId'].options = Object.freeze(response.data)
                })
              },
              clearFn: () => {
                this.errorTypes.TUNNEL.filterForm.siteId = ''
                this.errorTypes.TUNNEL.filterData['siteId'].options = []
              }
            },
            siteId: {
              key: 'siteId',
              type: 'select',
              title: '区间站场',
              placeholder: '所有区间站场',
              options: [],
              props: {
                label: 'siteName',
                value: 'id'
              },
              changeFn: () => {
              }
            },
            directionId: {
              key: 'directionId',
              type: 'select',
              clearable: true,
              title: '行别',
              placeholder: '所有行别',
              options: [],
              props: {
                label: 'directionName',
                value: 'id'
              },
              changeFn: () => {
              }
            },
            tunnelName: {
              key: 'tunnelName',
              type: 'input',
              placeholder: '隧道'
            }
          },
          columns: [
            { property: 'tunnelName', label: '隧道', formatter: row => row.tunnelName ? row.tunnelName : '' },
            { property: 'lineName', label: '线路', formatter: row => row.lineName ? row.lineName : '' },
            { property: 'siteName', label: '区间站场', formatter: row => row.siteNames ? row.siteNames.map(item => item.siteName).join('，') : '' },
            { property: 'beginRoad', label: '起始公里标', formatter: row => this.formatRoad(row.beginRoad) },
            { property: 'endRoad', label: '结束公里标', formatter: row => this.formatRoad(row.endRoad) }
          ],
          total: 0
        },
        ANCHOR: {
          chooseType: 'selectTable',
          type: 'ANCHOR',
          key: 'anchorNum',
          name: '锚段',
          interface: anchorList,
          list: [],
          data: {
            anchorId: 'id',
            anchorCode: 'anchorCode',
            anchorNum: 'anchorNum'
          },
          filterForm: {
            dataSysnKey: '',
            anchorNo: '',
            page: 1,
            size: 20
          },
          filterData: {
            lineId: {
              key: 'lineId',
              type: 'selectTree',
              title: '线路',
              placeholder: '所有线路',
              options: [],
              props: {
                label: 'label',
                value: 'id',
                parent: 'parentId',
                children: 'children'
              },
              changeFn: (vm, node) => {
              }
            },
            directionId: {
              key: 'directionId',
              type: 'select',
              title: '行别',
              placeholder: '所有行别',
              options: [],
              props: {
                label: 'directionName',
                value: 'id'
              },
              changeFn: () => {
              }
            },
            anchorNo: {
              key: 'anchorNo',
              type: 'input',
              placeholder: '锚段编号'
            }
          },
          columns: [
            { property: 'lineName', label: '线路', formatter: row => row.lineAttr ? row.lineAttr.lineName : '' },
            { property: 'siteName', label: '区间站场', formatter: row => row.siteName ? row.siteName : '' },
            { property: 'anchorNum', label: '锚段编号', formatter: row => row.anchorNo ? row.anchorNo : '' },
            { property: 'pillar', label: '起止支柱号', formatter: row => `${row.beginPillarId} - ${row.endPillarId}` }
          ],
          total: 0
        },
        PILLAR: {
          chooseType: 'selectTable',
          type: 'PILLAR',
          key: 'pillarNum',
          name: '支柱',
          interface: pillarList,
          list: [],
          data: {
            pillarId: 'id',
            pillarCode: 'pillarCode',
            pillarNum: 'pillarNum',
            roadMark: 'roadMark',
            anchorList: 'anchorList'
          },
          filterForm: {
            page: 1,
            size: 20,
            startPillar: '',
            dataSysnKey: '',
            endPillar: '',
            siteId: '',
            lineId: '',
            tunnelId: '',
            directionId: ''
          },
          filterData: {
            lineId: {
              key: 'lineId',
              type: 'selectTree',
              title: '线路',
              placeholder: '所有线路',
              options: [],
              props: {
                label: 'label',
                value: 'id',
                parent: 'parentId',
                children: 'children'
              },
              changeFn: (vm, node) => {
                this.errorTypes.PILLAR.filterForm.siteId = ''
                this.errorTypes.PILLAR.filterData['siteId'].options = []
                if (!node.id) return
                getSiteList({
                  dataSysnKey: this.currentRowObj.key,
                  lineId: node.id
                }).then(response => {
                  this.errorTypes.PILLAR.filterData['siteId'].options = Object.freeze(response.data)
                })
                getAllTunnelList({
                  lineId: node.id,
                  siteId: this.errorTypes.PILLAR.filterForm.siteId,
                  directionId: this.errorTypes.PILLAR.filterForm.directionId
                }).then(response => {
                  this.errorTypes.PILLAR.filterData['tunnelId'].options = Object.freeze(response.data)
                })
              },
              clearFn: () => {
                this.errorTypes.PILLAR.filterForm.siteId = ''
                this.errorTypes.PILLAR.filterData['siteId'].options = []
              }
            },
            siteId: {
              key: 'siteId',
              type: 'select',
              title: '区间站场',
              placeholder: '所有区间站场',
              options: [],
              props: { label: 'siteName', value: 'siteId' },
              changeFn: () => {
                getAllTunnelList({
                  lineId: this.errorTypes.PILLAR.filterForm.lineId,
                  siteId: this.errorTypes.PILLAR.filterForm.siteId
                }).then(response => {
                  this.errorTypes.PILLAR.filterData['tunnelId'].options = Object.freeze(response.data)
                })
              }
            },
            directionId: {
              key: 'directionId',
              type: 'select',
              clearable: true,
              title: '行别',
              placeholder: '所有行别',
              options: [],
              props: {
                label: 'directionName',
                value: 'directionId'
              },
              changeFn: () => {
                if (!this.errorTypes.PILLAR.filterForm.lineId) return
                getAllTunnelList({
                  lineId: this.errorTypes.PILLAR.filterForm.lineId,
                  siteId: this.errorTypes.PILLAR.filterForm.siteId,
                  directionId: this.errorTypes.PILLAR.filterForm.directionId
                }).then(response => {
                  this.errorTypes.PILLAR.filterData['tunnelId'].options = Object.freeze(response.data)
                })
              }
            },
            tunnelId: {
              key: 'tunnelId',
              type: 'select',
              title: '隧道',
              placeholder: '所有隧道',
              options: [],
              props: {
                label: 'tunnelName',
                value: 'tunnelId'
              },
              changeFn: () => {
              }
            },
            startPillar: {
              key: 'startPillar',
              type: 'input',
              placeholder: '开始支柱号'
            },
            endPillar: {
              key: 'endPillar',
              type: 'input',
              placeholder: '结束支柱号'
            }
          },
          columns: [
            { property: 'pillarNum', label: '支柱号', formatter: row => row.pillarNum ? row.pillarNum : '' },
            { property: 'lineName', label: '线路', formatter: row => row.lineName ? row.lineName : '' },
            { property: 'siteName', label: '区间站场', formatter: row => row.siteName ? row.siteName : '' },
            { property: 'directionName', label: '行别', formatter: row => row.directionName ? row.directionName : '' },
            { property: 'tunnelName', label: '隧道', formatter: row => row.tunnelName ? row.tunnelName : '' },
            { property: 'roadMark', label: '公里标', formatter: row => this.formatRoad(row.roadMark) }
          ],
          total: 0
        },
        JCW_DEVICE: {
          chooseType: 'selectTable',
          type: 'JCW_DEVICE',
          key: 'deviceName',
          name: '关键设备',
          interface: deviceList,
          list: [],
          data: {
            deviceId: 'id',
            deviceCode: 'deviceCode',
            deviceName: 'deviceName',
            devClassId: 'devClassAttr.devClassId',
            devClassCode: 'devClassAttr.devClassCode',
            devClassName: 'devClassAttr.devClassName'
          },
          filterForm: {
            keyName: '',
            page: 1,
            size: 20
          },
          filterData: {
            lineId: {
              key: 'lineId',
              type: 'selectTree',
              title: '线路',
              placeholder: '所有线路',
              options: [],
              props: {
                label: 'label',
                value: 'id',
                parent: 'parentId',
                children: 'children'
              },
              changeFn: (vm, node) => {
                this.errorTypes.JCW_DEVICE.filterForm['siteId'] = ''
                this.errorTypes.JCW_DEVICE.filterData['siteId'].options = []
                if (!node.id) return
                getSiteList({
                  dataSysnKey: this.currentRowObj.key,
                  lineId: node.id
                }).then(response => {
                  this.errorTypes.JCW_DEVICE.filterData['siteId'].options = Object.freeze(response.data)
                })
              },
              clearFn: () => {
                this.errorTypes.JCW_DEVICE.filterForm['siteId'] = ''
                this.errorTypes.JCW_DEVICE.filterData['siteId'].options = []
              }
            },
            siteId: {
              key: 'siteId',
              type: 'select',
              title: '区间站场',
              placeholder: '所有区间站场',
              options: [],
              props: {
                label: 'siteName',
                value: 'id'
              },
              changeFn: () => {
              }
            },
            directionId: {
              key: 'directionId',
              type: 'select',
              title: '行别',
              placeholder: '所有行别',
              options: [],
              props: {
                label: 'directionName',
                value: 'id'
              },
              changeFn: () => {
              }
            },
            keyName: {
              key: 'keyName',
              type: 'input',
              placeholder: '设备名称、支柱号'
            }
          },
          columns: [
            { property: 'lineName', label: '线路', formatter: row => row.lineAttr ? row.lineAttr.lineName : '' },
            { property: 'siteName', label: '区间站场', formatter: row => row.siteAttr ? row.siteAttr.siteName : '' },
            { property: 'directionName', label: '行别', formatter: row => row.directionList ? row.directionList.reduce((result, item) => `${result && `${result}，`}${item.directionName}`, '') : '' },
            { property: 'roadMark', label: '起止公里标', formatter: row => `${this.formatRoad(row.beginRoad)} -- ${this.formatRoad(row.endRoad)}` },
            { property: 'pillar', label: '支柱号', formatter: row => row.pillarList ? row.pillarList.map(item => item.pillarNum).join(',') : '' },
            { property: 'devClassName', label: '设备分类', formatter: row => row.devClassAttr ? row.devClassAttr.devClassShortName : '' },
            { property: 'deviceName', label: '设备名称', formatter: row => row.deviceName ? row.deviceName : '' }
          ],
          total: 0
        },
        DETECT_DEVICE: {
          chooseType: 'selectTable',
          type: 'DETECT_DEVICE',
          key: 'detectDeviceName',
          name: '检测设备',
          interface: device6cList,
          list: [],
          data: {
            detectDeviceId: 'id',
            detectDeviceCode: 'deviceCode',
            detectDeviceName: 'deviceName',
            cType: 'devClassId'
          },
          filterForm: {
            keyName: '',
            page: 1,
            size: 20
          },
          filterData: {
            keyName: {
              key: 'keyName',
              type: 'input',
              placeholder: '关键字查询'
            }
          },
          columns: [
            { property: 'deviceName', label: '设备名称', formatter: row => row.deviceName ? row.deviceName : '' },
            { property: 'siteName', label: '区间站场', formatter: row => row.siteAttr ? row.siteAttr.siteName : '' },
            { property: 'pillar', label: '支柱号', formatter: row => row.pillarAttr ? row.pillarAttr.pillarNum : '' },
            { property: 'positionDesc', label: '安装位置描述', formatter: row => row.positionDesc ? row.positionDesc : '' }
          ],
          total: 0
        },
        DEFECT_TYPE: {
          chooseType: 'selectTable',
          width: '700px',
          type: 'DEFECT_TYPE',
          key: 'DefectType',
          name: '缺陷类型',
          labelWidth: '110px',
          interface: getDefectTypePage,
          list: [],
          data: {
            userDefectTypeId: 'id',
            userDefectTypeCode: 'userDefectTypeCode',
            userDefectTypeName: 'userDefectTypeName',
            typeFullName: 'userDefectTypeName',
            idPath: 'idPath'
          },
          filterForm: {
            keyName: '',
            page: 1,
            size: 20
          },
          filterData: {
            keyName: {
              key: 'keyName',
              type: 'input',
              placeholder: '请输入名称、编码'
            }
          },
          columns: [
            { property: 'typeName', label: '缺陷分类名称', formatter: row => row.defectTypeName ? row.defectTypeName : '' },
            { property: 'levelName', label: '缺陷等级', width: '90px', formatter: row => row.defectGradeName ? row.defectGradeName : '' }
          ],
          total: 0
        },
        DEFECT_GRADE: {
          chooseType: 'selectTable',
          type: 'DEFECT_GRADE',
          key: 'userGradeName',
          name: '缺陷等级',
          labelWidth: '110px',
          interface: getDefectGradePage,
          list: [],
          data: {
            userGradeId: 'id',
            userGradeName: 'userGradeName',
            userSolveDays: 'userSolveDays',
            gradeId: 'gradeId'
          },
          filterForm: {
            keyName: '',
            page: 1,
            size: 20
          },
          filterData: {
            keyName: {
              key: 'keyName',
              type: 'input',
              placeholder: '请输入名称'
            }
          },
          columns: [
            { property: 'defectGradeName', label: '缺陷等级名称', formatter: row => row.defectGradeName ? row.defectGradeName : '' },
            { property: 'solveDays', label: '用户处理期限', formatter: row => row.solveDays ? row.solveDays : '' }
          ],
          total: 0
        },
        JCW_REPAIR_RECORD_STATE: {
          chooseType: 'select',
          type: 'JCW_REPAIR_RECORD_STATE',
          name: '检修状态',
          list: [
            { label: '良好', value: 1 },
            { label: '有缺陷', value: 2 }
          ],
          data: null,
          rules: {
            data: { type: 'number', required: true, message: '请选择', trigger: 'change' }
          }
        }
      },
      currentErrorType: {},
      selectData: [],
      currentRow: null,
      errorTypeList: [],
      keys: [],
      currentRowObj: {},
      nameActive: ''
    }
  },
  computed: {
    viewJson() {
      var errorList = {}
      for (var i in this.currentRowObj.consumerErrorList) {
        if (this.currentRowObj.consumerErrorList[i].errorField) {
          if (this.currentRowObj.consumerErrorList[i].errorType === 'LINE') {
            errorList.lineAttr = this.currentRowObj.errorData.lineAttr
          } else if (this.currentRowObj.consumerErrorList[i].errorType === 'DEPT') {
            errorList.deptAttr = this.currentRowObj.errorData.deptAttr
          } else if (this.currentRowObj.consumerErrorList[i].errorType === 'PILLAR') {
            errorList.pillarAttr = this.currentRowObj.errorData.pillarAttr
            errorList.lineAttr = this.currentRowObj.errorData.lineAttr
            errorList.directionAttr = this.currentRowObj.errorData.directionAttr
            errorList.siteAttr = this.currentRowObj.errorData.siteAttr
            errorList.tunnelAttr = this.currentRowObj.errorData.tunnelAttr
          } else if (this.currentRowObj.consumerErrorList[i].errorType === 'DIRECTION') {
            errorList.directionAttr = this.currentRowObj.errorData.directionAttr
          } else if (this.currentRowObj.consumerErrorList[i].errorType === 'TUNNEL') {
            errorList.tunnelAttr = this.currentRowObj.errorData.tunnelAttr
          } else if (this.currentRowObj.consumerErrorList[i].errorType === 'LINE_SITE') {
            errorList.siteAttr = this.currentRowObj.errorData.siteAttr
          } else if (this.currentRowObj.consumerErrorList[i].errorType === 'ANCHOR') {
            errorList.anchorAttr = this.currentRowObj.errorData.anchorAttr
          } else if (this.currentRowObj.consumerErrorList[i].errorType === 'TRACK') {
            errorList.trackAttr = this.currentRowObj.errorData.trackAttr
          }
        }
      }
      return errorList
    }
  },
  async created() {
    await this.getList()

    // // 从通用导入界面点过来
    // const { producerId, consumerId } = this.$route.params
    // this.addtionalParams = { producerId, consumerId }
    // this.getListPage()
  },
  activated() {
    const { producerId, consumerId } = this.$route.params
    this.addtionalParams = { producerId, consumerId }
    this.getListPage()
  },
  methods: {
    queryNodeClick(vm, node) {
      if (this.listLoading) return
      this.listQuery.bizType = vm.id
      this.search()
    },
    getList() {
      devClassList().then(response => {
        this.errorTypes.DEFECT_TYPE.filterData['devClassId'].options = Object.freeze(response.data)
      })
      getListBizTypeTree().then(response => {
        this.bizTypeTree = response.data
      })
      getDirectionList().then(response => {
        const data = Object.freeze(response.data)
        this.errorTypes.TUNNEL.filterData['directionId'].options = data
        this.errorTypes.TRACK.filterData['directionId'].options = data
        this.errorTypes.ANCHOR.filterData['directionId'].options = data
        this.errorTypes.PILLAR.filterData['directionId'].options = data
        this.errorTypes.JCW_DEVICE.filterData['directionId'].options = data
      })
      return Promise.all([getErrorType()]).then(response => {
        this.errorTypeList = Object.freeze(response[0].data)
        this.filterData['errorType'].options = this.keys = Object.freeze(response[0].data)
      })
    },
    getListPage() {
      this.listLoading = true
      getListPage(Object.assign({}, this.listQuery, this.addtionalParams))
        .then(response => {
          this.tableData = response.data.records
          this.total = response.data.total
          this.listLoading = false
        })
        .catch(_ => {
          this.listLoading = false
        })
    },
    search() {
      this.listQuery.page = 1
      this.getListPage()
    },
    // 重新校验
    reVerify() {
      const data = deepClone(this.listQuery)
      delete data.page
      delete data.size
      reVerify(data).then(response => {
        this.notifiySuccess('开始校验')
      })
    },
    // 左侧筛选错误类型
    chooseErrorType(type) {
      if (this.listLoading) return
      this.listQuery.errorType = type
      this.search()
    },
    // 展示源数据
    showJson(row) {
      this.currentRow = row
      this.dialog2.visible = true
    },
    // dialog切换校正
    handleClickError(index) {
      this.correct(this.currentRowObj, index)
    },
    // 初始校正下标,status=1为校正成功，status=0为未校正，都校正了到最后一个
    startCorrect(row, index) {
      for (var i in row.consumerErrorList) {
        if (row.consumerErrorList[i].status === 0) {
          this.correct(row, i)
          this.stepActive = i
          break
        } else if (i === row.consumerErrorList.length - 1) {
          this.correct(row, i)
          this.stepActive = i
        }
      }
    },
    // 获取线路
    getLineAndDirection(key) {
      getLineList({ dataSysnKey: key }).then(res => {
        const data = Object.freeze(res.data)
        this.errorTypes.LINE_SITE.filterData['lineId'].options = data
        this.errorTypes.PILLAR.filterData['lineId'].options = data
        this.errorTypes.TUNNEL.filterData['lineId'].options = data
        this.errorTypes.TRACK.filterData['lineId'].options = data
        this.errorTypes.ANCHOR.filterData['lineId'].options = data
        this.errorTypes.JCW_DEVICE.filterData['lineId'].options = data
      })
      getDirectionList({ dataSysnKey: key }).then(response => {
        const data = Object.freeze(response.data)
        this.errorTypes.TUNNEL.filterData['directionId'].options = data
        this.errorTypes.TRACK.filterData['directionId'].options = data
        this.errorTypes.ANCHOR.filterData['directionId'].options = data
        this.errorTypes.PILLAR.filterData['directionId'].options = data
        this.errorTypes.JCW_DEVICE.filterData['directionId'].options = data
      })
    },
    // 首页点击校正
    correct(row, i) {
      const index = parseFloat(i)
      this.currentRowObj = JSON.parse(JSON.stringify(row))
      this.currentRow = JSON.parse(JSON.stringify(row))
      this.getLineAndDirection(row.key)
      this.dialog = Object.assign({}, this.dialog, {
        form: {
          data: {},
          consumerErrorId: row.id,
          errorType: row.consumerErrorList[index].errorType,
          errorCode: row.consumerErrorList[index].errorCode,
          collectionName: '',
          dataSysnKey: row.key,
          // original: JSON.stringify(row.errorData),
          ruleFlag: 1
        }
      })
      this.nameActive = row.consumerErrorList[index].errorTypeName
      this.dialog1 = Object.assign({}, this.dialog1, {
        tableData: [],
        total: 0,
        listQuery: {
          page: 1,
          size: 20,
          errorType: row.consumerErrorList[index].errorType,
          errorCode: row.consumerErrorList[index].errorCode
        }
      })
      this.dialog.visible = true
      if (this.dialog.form.errorCode) {
        // 获取错误列表
        this.getErrorList()
      }

      // if (this.currentErrorType.type === row.consumerErrorList[index].errorType && this.currentErrorType.list.length) return

      this.currentErrorType.type = row.consumerErrorList[index].errorType
      this.currentErrorType = this.errorTypes[row.consumerErrorList[index].errorType]
      if (!this.currentErrorType.data) this.dialog.form.data = null
      /* if (this.currentErrorType.list.length) {
        this.selectData = this.currentErrorType.list
        return
      }*/
      this.selectData = []
      if (row.consumerErrorList[index].errorType) {
        this.listLoading = true
        this.currentErrorType.interface({ page: 1, size: 20, dataSysnKey: row.key }).then(response => {
          this.selectData = Object.freeze(response.data.records)
          this.currentErrorType.list = response.data.records
          this.currentErrorType.total = response.data.total
          this.listLoading = false
          if (row.consumerErrorList[index].status === 1) {
            if (this.dialog.form.errorType === 'PILLAR') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.pillarNum)
              for (var i in this.currentErrorType.list) {
                if (this.currentErrorType.list[i].pillarNum === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i])
                }
              }
            } else if (this.dialog.form.errorType === 'DEPT') {
              this.selectData = response.data
              this.currentErrorType.list = response.data
              this.currentErrorType.total = response.data.length
              this.currentErrorType.rowShowColor.value = row.consumerErrorList[index].correctData.deptName
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.deptName)
              for (var i1 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i1].deptName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i1])
                }
              }
            } else if (this.dialog.form.errorType === 'TRACK') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.trackName)
              for (var i2 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i2].trackName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i2])
                }
              }
            } else if (this.dialog.form.errorType === 'LINE') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.lineName)
              for (var i3 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i3].lineName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i3])
                }
              }
            } else if (this.dialog.form.errorType === 'LINE_SITE') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.siteName)
              for (var i4 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i4].siteName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i4])
                }
              }
            } else if (this.dialog.form.errorType === 'DEFECT_TYPE') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.userDefectTypeName)
              for (var i5 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i5].userDefectTypeName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i5])
                }
              }
            } else if (this.dialog.form.errorType === 'DIRECTION') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.directionName)
              for (var i6 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i6].directionName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i6])
                }
              }
            } else if (this.dialog.form.errorType === 'TUNNEL') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.tunnelName)
              for (var i7 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i7].tunnelName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i7])
                }
              }
            } else if (this.dialog.form.errorType === 'ANCHOR') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.anchorNum)
              for (var i8 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i8].anchorNum === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i8])
                }
              }
            } else if (this.dialog.form.errorType === 'JCW_DEVICE') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.deviceName)
              for (var i9 in this.currentErrorType.list) {
                if (this.currentErrorType.list[i9].deviceName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[i9])
                }
              }
            } else if (this.dialog.form.errorType === 'DETECT_DEVICE') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.deviceName)
              for (var j in this.currentErrorType.list) {
                if (this.currentErrorType.list[j].deviceName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[j])
                }
              }
            } else if (this.dialog.form.errorType === 'DEFECT_GRADE') {
              this.$set(this.dialog.form, 'collectionName', row.consumerErrorList[index].correctData.userGradeName)
              for (var j1 in this.currentErrorType.list) {
                if (this.currentErrorType.list[j1].userGradeName === this.dialog.form.collectionName) {
                  this.$set(this.dialog.form, 'data', this.currentErrorType.list[j1])
                }
              }
            }
          }
        })
      }
    },
    selectRow() {
      if (this.dialog.form.errorType === 'PILLAR') {
        for (var j2 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j2].pillarNum === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j2])
          }
        }
      } else if (this.dialog.form.errorType === 'DEPT') {
        for (var j3 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j3].deptName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j3])
          }
        }
      } else if (this.dialog.form.errorType === 'TRACK') {
        for (var j4 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j4].trackName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j4])
          }
        }
      } else if (this.dialog.form.errorType === 'LINE') {
        for (var j5 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j5].lineName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j5])
          }
        }
      } else if (this.dialog.form.errorType === 'LINE_SITE') {
        for (var j6 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j6].siteName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j6])
          }
        }
      } else if (this.dialog.form.errorType === 'DEFECT_TYPE') {
        for (var j7 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j7].userDefectTypeName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j7])
          }
        }
      } else if (this.dialog.form.errorType === 'DIRECTION') {
        for (var j8 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j8].directionName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j8])
          }
        }
      } else if (this.dialog.form.errorType === 'TUNNEL') {
        for (var j9 in this.currentErrorType.list) {
          if (this.currentErrorType.list[j9].tunnelName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[j9])
          }
        }
      } else if (this.dialog.form.errorType === 'ANCHOR') {
        for (var c in this.currentErrorType.list) {
          if (this.currentErrorType.list[c].anchorNum === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[c])
          }
        }
      } else if (this.dialog.form.errorType === 'JCW_DEVICE') {
        for (var c1 in this.currentErrorType.list) {
          if (this.currentErrorType.list[c1].deviceName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[c1])
          }
        }
      } else if (this.dialog.form.errorType === 'DETECT_DEVICE') {
        for (var c2 in this.currentErrorType.list) {
          if (this.currentErrorType.list[c2].deviceName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[c2])
          }
        }
      } else if (this.dialog.form.errorType === 'DEFECT_GRADE') {
        for (var c3 in this.currentErrorType.list) {
          if (this.currentErrorType.list[c3].userGradeName === this.dialog.form.collectionName) {
            this.$set(this.dialog.form, 'data', this.currentErrorType.list[c3])
          }
        }
      }
    },
    currentErrorTypeSearch() {
      this.currentErrorType.filterForm.page = 1
      this.currentErrorType.filterForm.dataSysnKey = this.currentRowObj.key
      this.currentErrorTypePage()
    },
    currentErrorTypePage() {
      this.listLoading = true
      this.currentErrorType.interface(this.currentErrorType.filterForm).then(response => {
        this.selectData = Object.freeze(response.data.records)
        this.currentErrorType.list = response.data.records
        this.currentErrorType.total = response.data.total
        this.listLoading = false
        // this.selectRow()
      })
    },
    // 获取错误列表
    getErrorList() {
      this.dialog1.listLoading = true
      getErrorList(Object.assign({}, this.dialog1.listQuery, this.addtionalParams))
        .then(response => {
          this.dialog1.tableData = response.data.records
          this.dialog1.total = response.data.total
          this.dialog1.listLoading = false
        })
        .catch(_ => {
          this.dialog1.listLoading = false
        })
    },
    // 查看所有错误条数
    showDetail() {
      this.dialog1.visible = true
    },
    // 部门 的错误类型 选择
    changeDept(vm, node) {
      this.dialog.form.data = {
        deptId: node.id,
        deptCode: node.obj.deptCode,
        deptName: node.label,
        parentCode: node.obj.parentCode
      }
    },
    clearDept() {
      this.dialog.form.data = {}
    },
    // 检修类型 的错误类型 选择
    changeSelect(val) {
      this.dialog.form.data = val
    },
    // 下拉表格的错误类型 选择
    changeData(data) {
      this.parseData(data)
    },
    parseData(data) {
      const result = {}
      Object.keys(this.currentErrorType.data).forEach(item => {
        const key = this.currentErrorType.data[item]
        result[item] = this.parseKey(key, data)
      })
      this.dialog.form.data = result
    },
    parseKey(key, data) {
      if (key.includes('.')) {
        const keys = key.split('.')
        let data1 = JSON.parse(JSON.stringify(data))
        for (let i = 0; i < keys.length; i++) {
          if (typeof data1[keys[i]] === 'object' && data1[keys[i]] !== null) {
            data1 = data1[keys[i]]
          } else {
            return data1[keys[i]]
          }
        }
      } else {
        return data[key]
      }
    },
    handleRowClick(row) {
      if (this.dialog.form.errorType === 'DEPT') {
        // 设置返现
        this.$set(this.dialog.form, 'collectionName', row.deptName)
        this.$set(this.dialog.form, 'data', row)
      }
      if (this.dialog.form.errorType === 'PILLAR') {
        this.$set(this.dialog.form, 'collectionName', row.pillarNum)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'TRACK') {
        this.$set(this.dialog.form, 'collectionName', row.trackName)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'LINE') {
        this.$set(this.dialog.form, 'collectionName', row.seclineName)
        this.dialog.form.data = {
          lineName: row.seclineName,
          lineCode: row.seclineNo,
          lineId: row.seclineId,
          railType: row.railType,
          lineType: row.seclineType,
          mCode: row.mCode,
          lineLevel: row.lineLevel
        }
      } else if (this.dialog.form.errorType === 'LINE_SITE') {
        this.$set(this.dialog.form, 'collectionName', row.siteName)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'DEFECT_TYPE') {
        this.$set(this.dialog.form, 'collectionName', row.userDefectTypeName)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'DIRECTION') {
        this.$set(this.dialog.form, 'collectionName', row.directionName)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'TUNNEL') {
        this.$set(this.dialog.form, 'collectionName', row.tunnelName)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'ANCHOR') {
        this.$set(this.dialog.form, 'collectionName', row.anchorNum)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'JCW_DEVICE') {
        this.$set(this.dialog.form, 'collectionName', row.deviceName)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'DETECT_DEVICE') {
        this.$set(this.dialog.form, 'collectionName', row.deviceName)
        this.$set(this.dialog.form, 'data', row)
      } else if (this.dialog.form.errorType === 'DEFECT_GRADE') {
        this.$set(this.dialog.form, 'collectionName', row.userGradeName)
        this.$set(this.dialog.form, 'data', row)
      }
    },
    updateData() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.dialog.loading = true
          saveRule(this.dialog.form).then(response => {
            if (this.stepActive < this.currentRowObj.consumerErrorList.length) {
              this.correct(this.currentRowObj, this.stepActive)
              this.stepActive++
              this.dialog.loading = false
              this.notifiySuccess('校正成功')
              this.dialog.visible = false
            } else {
              this.dialog.loading = false
              this.dialog.visible = false
              this.getListPage()
            }
          }).catch(_ => {
            this.dialog.loading = false
          })
        }
      })
    },
    beforeOpenDialog() {
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate()
      })
    },
    beforeCloseDialog() {
      this.getListPage()
    },
    hasValue(params) {
      const keys = Object.keys(params)
      return keys.length && keys.some(item => !!params[item])
    }
  }
}
</script>
<style lang="scss">
  .pretreatment-data-dialog1, .pretreatment-data-dialog2{
    .el-dialog{
      .el-dialog__body{
        height: calc(100vh - 70px);
        max-height: calc(90vh - 112px);
      }
    }
  }
  .pretreatment-data-dialog{
    .el-dialog{
      .el-dialog__body{
        height: calc(100vh - 70px);
        max-height: calc(90vh - 112px);
        padding: 0px 0 0;
        border-bottom: 1px solid #c0c4cc;
      }
      .el-dialog__footer {
        padding: 10px 30px 10px;
        .el-button {
          width: auto;
        }
      }
    }
    .pretreatment-data-dialog-box {
      display: flex;
      height: 100%;
    }
    .pretreatment-data-dialog-left{
      width: 480px;
      height: 100%;
      overflow: auto;
      border-right: 1px solid #c0c4cc;
      .view_json {
        height: calc(100% - 36px);
        padding-left: 15px;
        .jv-code {
          padding: 0;
        }
      }
    }
    .pretreatment-data-dialog-middle{
      flex: 1;
      height: 100%;
      .el-scrollbar__view {
        height: 100%;
      }
      .view_con {
        margin-top: 10px;
        margin-left:5px;
        height: calc(100% - 46px);
      }
      .el-tabs--border-card {
        border: none;
      }
      .el-icon-warning-outline {
        color: #F56C6C;
      }
      .el-steps--simple {
        padding: 8px 5%;
        margin-bottom: 10px;
      }
      // .el-icon-circle-check {
      //   color: #67c23a;
      // }
      // .el-step__head.is-finish {
      //   color: #67c23a;
      // }
      .el-form {
        padding: 0;
      }
    }
    .pretreatment-data-dialog-right{
      padding-left: 880px;
      padding-right: 10px;
      height: 100%;
    }
    .error-title{
      height: 36px;
      line-height: 36px;
      font-size: 20px;
      text-align: center;
      border-bottom: 1px solid #c0c4cc;
    }
    .error-sub-title{
      color: red;
      text-align: center;
      cursor: pointer;
      font-size: 15px;
      height: 36px;
      line-height: 36px;
      font-weight: bold;
    }
    .el-step__title {
      cursor: pointer;
    }
    .el-tabs__content {
      padding: 0px;
    }
    .el-icon-circle-check {
      color: #67c23a;
    }
  }
</style>
